/*
 * $HeadURL: $
 * $Id: $
 * Copyright (c) 2011 by Ericsson, all rights reserved.
 */

package android.test;

import java.io.IOException;
import java.io.InputStream;

import android.app.Activity;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.views.HelloGallery;
import android.views.HelloGridView;
import android.views.HelloLinearLayout;
import android.views.HelloListView;
import android.views.HelloRelativeLayout;
import android.views.HelloSpinner;
import android.views.HelloTabWidget;
import android.views.HelloTableLayout;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;

/**
 *
 * @author xyonton
 * @version $Revision: $
 */
public class Dashboard extends Activity {
    /** Revision of the class */
    public static final String _REV_ID_         = "$Revision: $";

    Button                     button;

    final private int          menuSetWallpaper = Menu.FIRST;

    final private int          menuAbout        = Menu.FIRST + 1;

    final private int          menuExit         = Menu.FIRST + 2;

    public static int          screenWidth;

    public static int          screenHeight;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        screenWidth = this.getWindowManager().getDefaultDisplay().getWidth();
        screenHeight = this.getWindowManager().getDefaultDisplay().getHeight();

        setTheme(R.style.Theme_1);
        super.onCreate(savedInstanceState);

        //Set to fullscreen
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.dashboard);
    }

    /* (non-Javadoc)
     * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // TODO Auto-generated method stub
        menu.add(0, menuSetWallpaper, Menu.NONE, "Set to wallpaper");
        menu.add(0, menuAbout, Menu.NONE, "About");
        menu.add(0, menuExit, Menu.NONE, "Quit...");
        return super.onCreateOptionsMenu(menu);
    }

    /* (non-Javadoc)
     * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // TODO Auto-generated method stub
        Toast toast;
        LinearLayout toastView;
        ImageView imageCodeProject;
        Resources resources = getBaseContext().getResources();
        InputStream is = resources.openRawResource(R.drawable.background);

        switch (item.getItemId()) {
            case 1:
                try {
                    this.setWallpaper(is);
                    Toast.makeText(Dashboard.this, "Done!", Toast.LENGTH_SHORT).show();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                break;
            case 2:
                toast = Toast.makeText(Dashboard.this, "APP by tjittty", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toastView = (LinearLayout) toast.getView();
                imageCodeProject = new ImageView(getApplicationContext());
                imageCodeProject.setImageResource(R.drawable.icon);
                toastView.addView(imageCodeProject, 0);
                toast.show();
                break;
            case 3:
                toast = Toast.makeText(Dashboard.this, "Good Bye :-)", Toast.LENGTH_SHORT);
                toast.setGravity(Gravity.CENTER, 0, 0);
                toastView = (LinearLayout) toast.getView();
                imageCodeProject = new ImageView(getApplicationContext());
                imageCodeProject.setImageResource(R.drawable.icon);
                toastView.addView(imageCodeProject, 0);
                toast.show();
                Dashboard.this.finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    // Hander onclick of button1
    public void LinearLayout(View v) {
        button = (Button) findViewById(R.id.button1);
        Intent intent = new Intent();
        intent.setClass(Dashboard.this, HelloLinearLayout.class);
        startActivity(intent);
    }

    // Hander onclick of button2
    public void RelativeLayout(View v) {
        button = (Button) findViewById(R.id.button2);
        Intent intent = new Intent();
        intent.setClass(Dashboard.this, HelloRelativeLayout.class);
        startActivity(intent);
    }

    // Hander onclick of button3
    public void TableLayout(View v) {
        button = (Button) findViewById(R.id.button3);
        Intent intent = new Intent();
        intent.setClass(Dashboard.this, HelloTableLayout.class);
        startActivity(intent);
    }

    // Hander onclick of button4
    public void GridView(View v) {
        button = (Button) findViewById(R.id.button4);
        Intent intent = new Intent();
        intent.setClass(Dashboard.this, HelloGridView.class);
        startActivity(intent);
    }

    // Hander onclick of button5
    public void TabLayout(View v) {
        button = (Button) findViewById(R.id.button5);
        Intent intent = new Intent();
        intent.setClass(Dashboard.this, HelloTabWidget.class);
        startActivity(intent);
    }

    // Hander onclick of button6
    public void ListView(View v) {
        button = (Button) findViewById(R.id.button6);
        Intent intent = new Intent();
        intent.setClass(Dashboard.this, HelloListView.class);
        startActivity(intent);
    }

    // Hander onclick of button7
    public void Spinner(View v) {
        button = (Button) findViewById(R.id.button7);
        Intent intent = new Intent();
        intent.setClass(Dashboard.this, HelloSpinner.class);
        startActivity(intent);
    }

    // Hander onclick of button8
    public void Gallery(View v) {
        button = (Button) findViewById(R.id.button8);
        Intent intent = new Intent();
        intent.setClass(Dashboard.this, HelloGallery.class);
        startActivity(intent);
    }

    // Hander onclick of button10
    public void Login(View v) {
        button = (Button) findViewById(R.id.button10);
        Intent intent = new Intent();
        intent.setClass(Dashboard.this, HelloWorldTJITTY.class);
        startActivity(intent);
    }

}
